package com.baiqian.doupo.douji;

import com.baiqian.doupo.capability.douqi.IDouQiCapability;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.potion.EffectInstance;
import net.minecraft.potion.Effects;
import net.minecraft.util.math.AxisAlignedBB;

import java.util.List;

import static net.minecraft.util.EntityPredicates.IS_ALIVE;

public class DouJi_XiZhang extends DouJi{
    public DouJi_XiZhang(){
        super("吸掌", 2,3,1,2*20,7*20,
                10,0.4,0.0,0.0,1,1,false,true);
    }

    @Override
    public void useEx(IDouQiCapability l, PlayerEntity entity) {
        double get_range = douqi_be_use/10;//每十点斗气+1范围
        AxisAlignedBB range = new AxisAlignedBB(
                entity.getPosX()- get_range, entity.getPosY() - get_range,  entity.getPosZ()-get_range,
                entity.getPosX() +get_range+1, entity.getPosY() + get_range+1,  entity.getPosZ()+get_range+1);//表示x，y，z所在的这一个格子
        List<LivingEntity> livingEntities = entity.world.getEntitiesWithinAABB(LivingEntity.class,range,IS_ALIVE);
        for (int i = 0; i < livingEntities.size(); ++i) {
            LivingEntity livingEntity = livingEntities.get(i);
            if(livingEntity.getPosX()!=entity.getPosX()||livingEntity.getPosY()!=entity.getPosY()||livingEntity.getPosZ()!=entity.getPosZ()) {
                EffectInstance effectinstance = new EffectInstance(Effects.SLOWNESS, 5, 0);
                livingEntity.addPotionEffect(effectinstance);
            }
            double x_speed = (livingEntity.getPosX()-entity.getPosX())/100;
            double y_speed = (livingEntity.getPosY()-entity.getPosY())/100;
            double z_speed = (livingEntity.getPosZ()-entity.getPosZ())/100;
            livingEntity.setPosition(livingEntity.getPosX()+x_speed,livingEntity.getPosY()+y_speed,livingEntity.getPosZ()+z_speed);
        }
    }

    @Override
    public void addEffect(LivingEntity entity) {

    }

    @Override
    protected void createEntity(IDouQiCapability l, PlayerEntity playerEntity) {

    }

}
